package main

import (
	"fmt"
	"math"
	"reflect"
	"strings"
)

var longVariable int

func main() {
	fmt.Println("hello world")
	fmt.Println(math.Floor(2.75), strings.ToTitle("hello world"))
	longVariable = 1 //全局长整型可以任何地方赋值
	fmt.Println("这是一个完整声明的变量被赋值", longVariable)
	shortVariable()
	funcInvoke()
}
func shortVariable() {
	var sex int = 1 //完整长变量声明，可以省略类型"int"部分
	fmt.Println(sex)
	var age = 10 // 省略了int部分, 编译器自己推导
	fmt.Println(age)

	var pi = 3.1415926
	fmt.Println(pi)

	var name = "wangshuaiyu"
	fmt.Println(name)

	height := 186 //局部可以声明
	fmt.Println("这是一个短变量类型声明的变量被赋值", height)
	height = 185
	fmt.Println("短变量类型声明的变量被修改", height)
}
func funcInvoke() {
	hello := "hello hello hello"
	fmt.Println("原始的hello:", hello)
	var adapter = strings.Replace(hello, "ello", "a", 3)
	fmt.Println("adapter的类型为", reflect.TypeOf(adapter))
	fmt.Println("hello被转换成了：", adapter)

	haha := "haha"
	replacer := strings.NewReplacer("a", "ello")
	fmt.Println("replacer的类型为", reflect.TypeOf(replacer))
	hahaToHello := replacer.Replace(haha)
	fmt.Println("haha被转化成了: ", hahaToHello)

}
